<!--
 * @Description  : 预览 下载pdf 
 * @Author       : zhao
 * @Date         : 2022-07-21 13:43:56
 * @LastEditors  : zhao
 * @LastEditTime : 2023-01-10 15:51:41
-->

<template>
    <div class="zpdf">
        <pdf v-for="i in numPages" :key="i" :src="src" :page="i" ref="myPdfComponent"></pdf>
    </div>
</template>

<script>
import pdf from "vue-pdf-signature"
// 解决部分文字不显示的问题
import CMapReaderFactory from "vue-pdf-signature/src/CMapReaderFactory.js"

export default {
    name: "",
    data() {
        return {
            src: "",
            numPages: 0,
            page: 1,
            currentPage: 0,
            dialogVisible: false,
        }
    },
    watch: {
        "$store.state.borrowForm.previewType": {
            handler: function (val, oldVal) {
                this.goPreview(val.url)
            },
            immediate: true,
            deep: true,
        },
    },
    props: {
        url: String,
    },
    components: { pdf },

    computed: {},

    mounted() {},

    methods: {
        goPreview() {
            this.src = pdf.createLoadingTask({ url: this.$store.state.borrowForm.previewType.url, CMapReaderFactory })

            this.src.promise.then((pdf) => {
                this.numPages = pdf.numPages
            })
        },
    },
}
</script>
<style lang='scss' scoped>
.zpdf {
}
</style>